package org.langcom.state;

import org.langcom.logic.ILogic;
import org.langcom.logic.LogicException;
/**
 * @author nemo
 *
 */
public abstract class AbstractAction implements ICommonAction {

	protected String text;
	protected ILogic logic;
	protected String description;

	public AbstractAction(String text, ILogic logic, String description) {
		this(text, description);
		this.logic = logic;
	}

	public AbstractAction(String text, String description) {
		this.text = text;
		this.description = description;
	}

	public String getDescription() {
		return description;
	}

	public ILogic getLogic() {
		return logic;
	}

	public String getText() {
		return text;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setLogic(ILogic logic) {
		this.logic = logic;
	}

	public void setText(String text) {
		this.text = text;
	}

	public void run() throws Exception {
		if (logic != null) {
			if (logic.check()) {
				runChecked();
			} else {
				throw new LogicException(logic);
			}
		} else {
			runChecked();
		}
	}

}
